<!--
 * @页面名称:主页面全文权限管理
 * @描述: 
 * @作者: 
 * @Date:
-->
<template>
  <div>
    <modal v-model:visible="config.visible" :title="config.title" width="850" @ok="ok">
      <div style="height: 400px">
        <stable :columns="tableSetting.columns" :data="tableSetting.data" @selectionChange="selectionChange"></stable>
      </div>
      <el-form :model="formData" ref="formRef">
        <el-row>
          <el-col :span="6">
            <el-form-item label="是否禁止显示:" prop="isShow">
              <el-checkbox type="number" v-model="formData.isShow"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否禁止打开全文:" prop="isOpen">
              <el-checkbox type="number" v-model="formData.isOpen"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否禁止打印全文:" prop="isPrint">
              <el-checkbox type="number" v-model="formData.isPrint"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否禁止下载全文:" prop="isDownload">
              <el-checkbox type="number" v-model="formData.isDownload"></el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </modal>
  </div>
</template>

<script setup lang="ts">
import { reactive, onMounted } from "vue";
import { useDynamicStore } from "@/stores/modules/dynamic";
import { useCatalogStore } from "@/stores/modules/catalog";
import useCurrentInstance from "@/utils/useCurrentInstance";

const { proxy } = useCurrentInstance();
const props = defineProps({
  config: {
    type: Object,
    default: () => {
      return {};
    }
  },
  data: {
    type: Object,
    default: () => {
      return {};
    }
  },
  fulltextData: {
    type: Array,
    default: () => {
      return [];
    }
  }
});
// 表格配置
const tableSetting = reactive({
  columns: [
    { type: "checkbox", width: 55 },
    { field: "G_Name", title: "角色名称", sortable: true }
  ],
  data: [],
  selectionData: []
});
// 表单绑定字段
const formData = reactive({
  isShow: false,
  isOpen: false,
  isPrint: false,
  isDownload: false
});
// 获取pinia中的数据
const dynamicStore = useDynamicStore();
const catalogStore = useCatalogStore();
// 获取表格数据
const getTableData = () => {
  proxy.$vueAxios.get("Master_Base_Groups/Get", { order: "G_Order asc" }).then((res: any) => {
    res.List.sort((a: { G_Order: number }, b: { G_Order: number }) => a.G_Order - b.G_Order);
    tableSetting.data = res.List;
  });
};
// 表格多选
const selectionChange = (val: any) => {
  tableSetting.selectionData = val;
};
// 确认事件
const ok = () => {
  props.config.visible = false;
  if (props.config.type === "folder") {
    const params = {
      catalog_ID: catalogStore.treeNode.catalog_ID,
      dataIDList: dynamicStore.tableSelect.map((item: any) => item.Record_ID),
      fmT_ID: dynamicStore.tableSelect[0].FMT_ID,
      fM_ID: dynamicStore.tableSelect[0].FM_ID,
      fonds_ID: dynamicStore.tableSelect[0].Fonds_ID,
      gidList: tableSetting.data.map((item: any) => item.G_ID),
      isBanOnDisplay: formData.isShow,
      isBanOnOpen: formData.isOpen,
      isBanOnPrint: formData.isPrint,
      isBanOnDownload: formData.isDownload
    };
    proxy.$vueAxios.post("MasterBaseGUDataPermission/AddList", params).then((res: any) => {
      if (res.Mark) {
        proxy.$message.success("权限添加成功");
      }
    });
  } else if (props.config.type === "child") {
    const params = {
      catalog_ID: catalogStore.treeNode.catalog_ID,
      dataIDList: dynamicStore.childTableSelect.map((item: any) => item.Record_ID),
      fmT_ID: dynamicStore.childTableSelect[0].FMT_ID,
      fM_ID: dynamicStore.childTableSelect[0].FM_ID,
      fonds_ID: dynamicStore.childTableSelect[0].Fonds_ID,
      gidList: tableSetting.data.map((item: any) => item.G_ID),
      isBanOnDisplay: formData.isShow,
      isBanOnOpen: formData.isOpen,
      isBanOnPrint: formData.isPrint,
      isBanOnDownload: formData.isDownload
    };
    proxy.$vueAxios.post("MasterBaseGUDataPermission/AddList", params).then((res: any) => {
      if (res.Mark) {
        proxy.$message.success("权限添加成功");
      }
    });
  } else if (props.config.type === "fullText") {
    const params = {
      data_ID: props.data.Record_ID,
      fmT_ID: props.data.FMT_ID,
      fM_ID: props.data.FM_ID,
      fonds_ID: props.data.Fonds_ID,
      aiidList: props.fulltextData.map((item: any) => item.AI_ID),
      gidList: tableSetting.data.map((item: any) => item.G_ID),
      isBanOnDisplay: formData.isShow,
      isBanOnOpen: formData.isOpen,
      isBanOnPrint: formData.isPrint,
      isBanOnDownload: formData.isDownload
    };
    proxy.$vueAxios.post("MasterBaseGUDataPermission/AddAllInfosList", params).then((res: any) => {
      if (res.Mark) {
        proxy.$message.success("权限添加成功");
      }
    });
  }
};
onMounted(() => {
  getTableData();
});
</script>

<style scoped lang="scss"></style>
